#include <iostream>
#include "GraphFlowMatrix.h"

using namespace std;

GraphFlowMatrix::GraphFlowMatrix() : GraphFlow(), GraphOrientedMatrix() { //cerr<<"Constructeur par défaut de GraphFlowMatrix"<<endl;
}

GraphFlowMatrix::GraphFlowMatrix(GraphFlow &g) : GraphFlow(g.getSummitNb(),g.getEdgesNb()), GraphOrientedMatrix(g)
{
  //cerr<<"Constructeur par copie de GraphFlowMatrix"<<endl;
  summit_nb = g.getSummitNb();
  edges_nb = g.getEdgesNb();
  flow = new flow_t*[getSummitNb()];
  capacity = new flow_t*[getSummitNb()];

  for (summit_t i=0; i<getSummitNb(); i++)
  {
    flow[i] = new flow_t[getSummitNb()];
    capacity[i] = new flow_t[getSummitNb()];

    for (summit_t j=0; j<getSummitNb(); j++)
    {
      flow[i][j]=g.getFlow(i,j);
      capacity[i][j]=g.getCapacity(i,j);
    }
  }
}

GraphFlowMatrix::GraphFlowMatrix(summit_t n, edges_t m) : GraphFlow(n,m), GraphOrientedMatrix(n,m)
{
  //cerr<<"Constructeur paramétré de GraphFlowMatrix"<<endl;
  summit_nb = n;
  edges_nb = m;
  flow = new flow_t*[getSummitNb()];
  capacity = new flow_t*[getSummitNb()];

  for (summit_t i=0; i<getSummitNb(); i++)
  {
    flow[i] = new flow_t[getSummitNb()];
    capacity[i] = new flow_t[getSummitNb()];

    for (summit_t j=0; j<getSummitNb(); j++)
    {
      flow[i][j]=0;
      capacity[i][j]=0;
    }
  }
}

GraphFlowMatrix::~GraphFlowMatrix()
{
  for (summit_t i=0; i<getSummitNb(); i++)
  {
    delete [] flow[i];
    delete [] capacity[i];
  }
  delete [] flow;
  delete [] capacity;
}

flow_t GraphFlowMatrix::getFlow(summit_t i, summit_t j) const
{
  if (areConnected(i,j))
    return flow[i][j];
  else return -1;
}

flow_t GraphFlowMatrix::getCapacity(summit_t i, summit_t j) const
{
   if (areConnected(i,j))
   return capacity[i][j];
  else return -1;
}

void GraphFlowMatrix::setFlow(summit_t i, summit_t j, flow_t f)
{
  if (areConnected(i,j))
    flow[i][j]=f;
}

void GraphFlowMatrix::setCapacity(summit_t i, summit_t j, flow_t c)
{
  if (areConnected(i,j))
    capacity[i][j]=c;
}
